package com.linkhub.oms.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.github.yulichang.annotation.EntityMapping;
import com.linkhub.oms.common.enums.product.LocalProductSearchTypeEnum;
import com.linkhub.oms.entity.typehandler.QtFastjsonTypeHandler;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.FieldNameConstants;

import javax.persistence.Transient;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 本地商品表
 * </p>
 *
 * @author echo
 * @since 2024-03-28
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName(value = "t_local_product", autoResultMap = true)
@ApiModel(value = "LocalProductEntity对象", description = "本地商品表")
@FieldNameConstants
public class LocalProductEntity implements Serializable {

    @ApiModelProperty(value = "主键")
    @TableId(value = "Fid", type = IdType.AUTO)
    private Long id;

    @ApiModelProperty(value = "WMS产品ID")
    @TableField("Fitem_id")
    private String itemId;

    @ApiModelProperty(value = "用户id")
    @TableField("Fuser_id")
    private String userId;

    @ApiModelProperty(value = "产品类型: 1-单个产品（默认）；2-包材；3-组合产品")
    @TableField("Fproduct_type")
    private Integer productType;

    @ApiModelProperty(value = "本地商品skuId")
    @TableField("Fsku_id")
    private String skuId;

    @ApiModelProperty(value = "sku")
    @TableField("Fsku")
    private String sku;

    @ApiModelProperty(value = "spu")
    @TableField("Fspu")
    private String spu;

    @ApiModelProperty(value = "英文品名")
    @TableField("Fproduct_en_title")
    private String productEnTitle;

    @ApiModelProperty(value = "中文品名")
    @TableField("Fproduct_c_title")
    private String productCTitle;

    @ApiModelProperty(value = "类目编码")
    @TableField("Fcategory_code")
    private String categoryCode;

    @ApiModelProperty(value = "类目名称")
    @TableField("Fcategory_name")
    private String categoryName;

    @ApiModelProperty(value = "upc码")
    @TableField("Fupc")
    private String upc;

    @ApiModelProperty(value = "fnsku码")
    @TableField("Ffnsku")
    private String fnsku;

    @ApiModelProperty(value = "系统商品条码")
    @TableField("Fsys_bar_code")
    private String sysBarCode;

    @ApiModelProperty(value = "其他商品条码")
    @TableField("Fother_code")
    private String otherCode;

    @ApiModelProperty(value = "型号")
    @TableField("Fmodel")
    private String model;

    @ApiModelProperty(value = "品牌")
    @TableField("Fbrand")
    private String brand;

    @ApiModelProperty(value = "采购价格")
    @TableField("Fpurchase_price")
    private String purchasePrice;

    @ApiModelProperty(value = "图片")
    @TableField("Fimg_url")
    private String imgUrl;

    @ApiModelProperty(value = "图片2")
    @TableField("Fimg2")
    private String img2;

    @ApiModelProperty(value = "图片3")
    @TableField("Fimg3")
    private String img3;

    @ApiModelProperty(value = "物流属性：1-带磁；2-纯电；3-液体；4-粉末；5-易碎；6-膏体；7-化妆品；8-纺织品;9-内置电池小于100W*H" +
            "10-内置电池>=100W*H; 11-配套电池小于100W*H; 12-配套电池>=100*H; 13-成人用品;14-FDA认证产品;15-原木；16-木质品；17-服装类")
    @TableField(value = "Flogistics_attribute", typeHandler = QtFastjsonTypeHandler.class)
    private List<Integer> logisticsAttribute;

    @ApiModelProperty(value = "包材类型：1-飞机盒；2-平口箱；3-缓冲袋；4-不干胶；5-胶带；6-衬纸")
    @TableField("Fpacking_material_type")
    private Integer packingMaterialType;

    @ApiModelProperty(value = "是否记录库存: 0-否；1-是")
    @TableField("Fis_record_stock")
    private Integer isRecordStock;

    @ApiModelProperty(value = "规格尺寸单位: 1-公制；2-英制")
    @TableField("Fspecification_unit")
    private Integer specificationUnit;

    @ApiModelProperty(value = "产品/包材信息，多个信息使用-拼接：长度(英寸)-宽度(英寸)-高度(英寸)-重量(盎司)")
    @TableField("Fspecification_product_info")
    private String specificationProductInfo;

    @ApiModelProperty(value = "包材展开信息，多个信息使用-拼接：长度(英寸)-宽度(英寸)-高度(英寸)")
    @TableField("Fspecification_wrap_unfold_info")
    private String specificationWrapUnfoldInfo;

    @ApiModelProperty(value = "包装单位: 1-公制；2-英制")
    @TableField("Fwrap_unit")
    private Integer wrapUnit;

    @ApiModelProperty(value = "包装产品信息，多个信息使用-拼接：长度(英寸)-宽度(英寸)-高度(英寸)-重量(盎司)")
    @TableField("Fwrap_product_info")
    private String wrapProductInfo;

    @ApiModelProperty(value = "默认包材，值为包材的skuId")
    @TableField("Fdefault_packing_material")
    private String defaultPackingMaterial;

    @ApiModelProperty(value = "包装类型，1-盒装；2-袋装")
    @TableField("Fwrap_type")
    private Integer wrapType;

    @ApiModelProperty(value = "Ready2Ship：0-否；1-是")
    @TableField("Fready_ship")
    private Integer readyShip;

    @ApiModelProperty(value = "海关编码")
    @TableField("Fhs_code")
    private String hsCode;

    @ApiModelProperty(value = "用途中文")
    @TableField("Fc_ppurpose")
    private String cPurpose;

    @ApiModelProperty(value = "用途英文")
    @TableField("Fe_ppurpose")
    private String ePurpose;

    @ApiModelProperty(value = "材质中文")
    @TableField("Fc_material")
    private String cMaterial;

    @ApiModelProperty(value = "用途英文")
    @TableField("Fe_material")
    private String eMaterial;

    @ApiModelProperty(value = "其它申报要素")
    @TableField("Fother_declaration_elements")
    private String otherDeclarationElements;

    @ApiModelProperty(value = "仓库人员Id")
    @TableField("Fstore_user_id")
    private String storeUserId;

    @ApiModelProperty(value = "复核图片")
    @TableField("Fimg_url_recheck")
    private String imgUrlRecheck;

    @ApiModelProperty(value = "复核图片2")
    @TableField("Fimg2_recheck")
    private String img2Recheck;

    @ApiModelProperty(value = "复核图片3")
    @TableField("Fimg3_recheck")
    private String img3Recheck;

    @ApiModelProperty(value = "复核物流属性：1-带磁；2-纯电；3-液体；4-粉末；5-易碎；6-膏体；7-化妆品；8-纺织品;9-内置电池小于100W*H" +
            "10-内置电池>=100W*H; 11-配套电池小于100W*H; 12-配套电池>=100*H; 13-成人用品;14-FDA认证产品;15-原木；16-木质品；17-服装类")
    @TableField(value = "Flogistics_attribute_recheck", typeHandler = QtFastjsonTypeHandler.class)
    private List<Integer> logisticsAttributeRecheck;

    @ApiModelProperty(value = "复核规格尺寸单位: 1-公制；2-英制")
    @TableField("Fspecification_unit_recheck")
    private Integer specificationUnitRecheck;

    @ApiModelProperty(value = "复核产品/包材信息，多个信息使用-拼接：长度-宽度-高度-重量")
    @TableField("Fspecification_product_info_recheck")
    private String specificationProductInfoRecheck;

    @ApiModelProperty(value = "复核包材展开信息，多个信息使用-拼接：长度-宽度-高度")
    @TableField("Fspecification_wrap_unfold_info_recheck")
    private String specificationWrapUnfoldInfoRecheck;

    @ApiModelProperty(value = "复核包装类型，1-盒装；2-袋装")
    @TableField("Fwrap_type_recheck")
    private Integer wrapTypeRecheck;

    @ApiModelProperty(value = "复核Ready2Ship：0-否；1-是")
    @TableField("Fready_ship_recheck")
    private Integer readyShipRecheck;

    @ApiModelProperty(value = "创建时间")
    @TableField("Fcreated_time")
    private LocalDateTime createdTime;

    @ApiModelProperty(value = "修改时间")
    @TableField("Fupdate_time")
    private LocalDateTime updateTime;

    @ApiModelProperty(value = "本地商品对应的申报信息")
    @TableField(exist = false)
    @Transient
    @EntityMapping(thisField = LocalProductEntity.Fields.skuId, joinField = LocalProductAmountDeclaresInfoEntity.Fields.skuId)
    private List<LocalProductAmountDeclaresInfoEntity> localProductAmountDeclaresInfos;

    public static SFunction<LocalProductEntity, ?> convertSearchField( LocalProductSearchTypeEnum searchTypeEnum ) {
        if (LocalProductSearchTypeEnum.SKU.equals(searchTypeEnum)) {
            return LocalProductEntity::getSku;
        }

        if (LocalProductSearchTypeEnum.SPU.equals(searchTypeEnum)) {
            return LocalProductEntity::getSpu;
        }

        return LocalProductEntity::getProductEnTitle;

    }


}
